#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/wait.h>
#include <stdlib.h>

char* const newEnv = "MYENV=12345";
char* const addEnv[] = {
	"MYEVN=123456",
	"MYENV=234567",
	NULL
};


extern char** environ;
int main()
{
	printf("main程序开始运行\n");
	pid_t id = fork();
	if(id==0 )
	{
	//	char* const argv[] = 
	//	{
	//		"ls",
	//		"-l",
	//		"-a",
	//		NULL
	//	};
		//char* const env[] = {
		//	(char*const) "MYENV=12345",
		//	NULL
		//};
		char* const argv[] = 
		{	
			"other",
			"-a",
			"-b",
			"-c",
			NULL
		};

		sleep(1);
		//putenv(newEnv);
		printf("子进程pid:%d\n",getpid());
		for(int i =0;addEnv[i];i++)
		{
			putenv(addEnv[i]);
		}
		execvpe("./other",argv,environ);	
		//execv("./other",argv);
		//execv("/usr/bin/ls",argv);
		//execl("/usr/bin/ls","/usr/bin/ls","-a","-l",NULL);	
		//execl("./other","other",NULL);
		//execlp("/usr/bin/ls","ls","-a","-l",NULL);
		exit(1);
	}

	waitpid(-1,NULL,0);
	printf("main程序结束运行\n");
	return 0;
}
//int main()
//{
//	printf("main程序开始运行\n");
//	//execl("/usr/bin/ls","/usr/bin/ls","-a","-l",NULL);
//	execl("/usr/bin/ls","ls","-a","-l",NULL);
////	execl("/usr/bin/python3","python3","test.py",NULL);
////	execl("./other","other",NULL);
//	printf("main程序结束运行\n");
//	return 0;
//}

